<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <!-- TopJUI框架样式 -->
    <link type="text/css" href="../../topjui/themes/default/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="../../topjui/themes/default/topjui.blue.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="../../static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- layui框架样式 -->
    <link type="text/css" href="../../static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="../../static/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="../../static/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="../../static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="../../topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="../../topjui/js/locale/topjui.lang.zh_CN.js"></script>
    <!-- layui框架js -->
    <script type="text/javascript" src="../../static/plugins/layui/layui.js" charset="utf-8"></script>
</head>

<body>
<!-- layout布局 开始 -->

<div data-toggle="topjui-layout" data-options="fit:true">
    <div data-options="region:'center',title:'',fit:true,split:true,border:false">
        <!-- datagrid表格 -->
        <table data-toggle="topjui-datagrid"
               data-options="id: 'productDg',
               fitColumns:true,
               showFooter:true,
                url: '../../json/datagrid/product-list-footer.json',
                filter: [{
                    field: 'name',
                    type: 'textbox',
                    op: ['contains', 'equal', 'notequal', 'less', 'greater']
                }, {
                    field: 'code',
                    type: 'combobox',
                    options: {
                        valueField: 'label',
                        textField: 'value',
                        data: [{
                            label: '2103',
                            value: '2103'
                        }, {
                            label: '5103',
                            value: '5103'
                        }, {
                            label: '1204',
                            value: '1204'
                        }]
                    },
                    op: ['contains', 'equal', 'notequal', 'less', 'greater']
                }, {
                    field: 'spec',
                    type: 'combobox',
                    options: {
                        valueField: 'label',
                        textField: 'value',
                        multiple: true,
                        data: [{
                            label: 'KC-W200SW',
                            value: 'KC-W200SW'
                        }, {
                            label: '白色LR-1688BY-2',
                            value: '白色LR-1688BY-2'
                        }, {
                            label: '银灰色BCD-339WBA 339',
                            value: '银灰色BCD-339WBA 339'
                        }]
                    },
                    op: ['contains', 'equal', 'notequal', 'less', 'greater']
                }]">
            <thead>
            <tr>
                <th data-options="field:'uuid',title:'UUID',checkbox:true"></th>
                <th data-options="field:'name',title:'商品名称',sortable:true,width:100"></th>
                <th data-options="field:'spec',title:'规格型号',sortable:true,width:100"></th>
                <th data-options="field:'code',title:'商品编号',sortable:true,width:50"></th>
                <th data-options="field:'sale_price',title:'销售单价',sortable:true,width:50"></th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<!-- layout布局 结束 -->

<!-- 表格工具栏开始 -->
<div id="productDg-toolbar" class="topjui-toolbar"
     data-options="grid:{
           type:'datagrid',
           id:'productDg'
       }">
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'openDialog',
       extend: '#productDg-toolbar',
       iconCls: 'fa fa-plus',
       dialog:{
           id:'userAddDialog',
           title:'多选项卡布局的表单',
           href:_ctx + '/html/complex/dialog_add.html',
           buttonsGroup:[
               {text:'保存',url:_ctx + '/json/response/success.json',iconCls:'fa fa-plus',handler:'ajaxForm',btnCls:'topjui-btn-green'}
           ]
       }">新增</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method: 'openDialog',
            extend: '#productDg-toolbar',
            iconCls: 'fa fa-pencil',
            btnCls: 'topjui-btn-green',
            grid: {
                type: 'datagrid',
                id: 'productDg'
            },
            dialog: {
                title:'普通布局的表单',
                height: 550,
                href: _ctx + '/html/complex/dialog_edit.html?uuid={uuid}',
                url: _ctx + '/json/datagrid/product-detail.json?uuid={uuid}',
                buttonsGroup: [
                    {
                        text: '自定义方法',
                        url: _ctx + '/json/response/success.json',
                        iconCls: 'fa fa-cog',
                        handler: myQuery,
                        btnCls: 'topjui-btn-brown'
                    },
                    {
                        text: '更新',
                        url: _ctx + '/json/response/save2.json',
                        iconCls: 'fa fa-save',
                        handler: 'ajaxForm',
                        btnCls: 'topjui-btn-green'
                    }
                ]
            }">编辑</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method: 'doAjax',
       extend: '#productDg-toolbar',
       iconCls: 'fa fa-cog',
       btnCls: 'topjui-btn-red',
       grid: {
           type: 'datagrid',
           id: 'productDg',
           param:'uuid2:uuid,code',
           uncheckedMsg:'请先选择你要批量操作的数据'
       },
       url:_ctx + '/json/response/success.json'
       ">批量操作</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'doAjax',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-brown',
       iconCls:'fa fa-trash',
       confirmMsg:'这个是勾选复选框实现多条数据的Ajax删除提交操作，提交grid.param中指定的参数值',
       grid: {uncheckedMsg:'请先勾选要删除的数据',param:'uuid:uuid,code:code',updateRow:true},
       url:_ctx + '/json/response/success.json'">删除</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'filter',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-black'">过滤</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'search',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-blue'">查询</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'import',
       extend: '#productDg-toolbar',
       grid:{
           type:'datagrid',
           id:'productDg'
       },
       iconCls:'fa fa-cloud-upload',
       btnCls:'topjui-btn-orange',
       uploadUrl:_ctx + '/json/response/upload.json',
       url:_ctx+'/json/response/success.json'">导入</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'export',
       extend: '#productDg-toolbar',
       iconCls:'fa fa-cloud-download',
       btnCls:'topjui-btn-red',
       url:_ctx + '/json/response/export.html'">导出</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'openTab',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-purple',
       tab:{
           title:'Panel表单新增',
           href:_ctx + '/html/complex/panel_add.html'
       }">标签页（新增）</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'openTab',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-purple',
       tab:{
           title:'Panel表单编辑',
           href:_ctx + '/html/complex/panel_edit.html?uuid={uuid}'
       }">标签页（编辑）</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'openWindow',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-green',
       href:'http://www.topjui.com?uuid={uuid}'">新窗口</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="method:'request',
       extend: '#productDg-toolbar',
       btnCls:'topjui-btn-brown',
       url:_ctx + '/json/response/success.json?uuid={uuid}&code={code}'">普通请求</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="btnCls:'topjui-btn-black',
       onClick:myQuery">自定义方法</a>
    <a href="javascript:void(0)"
       data-toggle="topjui-menubutton"
       data-options="menu:'#exportSubMenu',
       btnCls:'topjui-btn-blue',
       hasDownArrow:true,
       iconCls:'fa fa-list'">更多</a>
    <div id="exportSubMenu" style="width:150px;" data-options="onClick:menuHandler">
        <div data-options="method:'openDialog',id:'aabb',
        extend: '#productDg-toolbar',
        iconCls: 'fa fa-plus',
        dialog:{
            id:'userAddDialog',
            title:'多选项卡布局的表单',
            href:_ctx + '/html/complex/dialog_add.html',
            buttonsGroup:[
                {text:'保存',url:_ctx + '/json/response/success.json',iconCls:'fa fa-plus',handler:'ajaxForm',btnCls:'topjui-btn-green'}
            ]
        }">
            打开新增窗体
        </div>
        <div data-options="method:'doAjax',iconCls:'fa fa-file-pdf-o',
        confirmMsg:'这个是勾选复选框实现多条数据的Ajax删除提交操作，提交grid.param中指定的参数值',
        extend: '#productDg-toolbar',
        grid: {uncheckedMsg:'请先勾选要删除的数据',param:'uuid:uuid,code:code'},
        url:_ctx + '/json/response/success.json'">
            发送Ajax请求
        </div>
        <div data-options="method:'export',iconCls:'fa fa-file-excel-o',url: _ctx + '/json/response/export.html'">
            导出EXCEL列表
        </div>
        <div data-options="method:'request',extend: '#productDg-toolbar',iconCls:'fa fa-file-excel-o',url:_ctx + '/json/response/success.json?uuid={uuid}'">
            导出EXCEL报表
        </div>
        <div data-options="method:'request',extend: '#productDg-toolbar',iconCls:'fa fa-file-word-o',url:_ctx + '/json/response/success.json?uuid={uuid}'">
            导出WORD报表
        </div>
    </div>
    <form id="queryForm" class="search-box">
        <input type="text" name="name" data-toggle="topjui-textbox"
               data-options="id:'name',prompt:'产品名称',width:100">
        <input type="text" name="code" data-toggle="topjui-textbox"
               data-options="id:'code',prompt:'产品型号',width:100">
        <a href="javascript:void(0)"
           data-toggle="topjui-menubutton"
           data-options="method:'query',
           iconCls:'fa fa-search',
           btnCls:'topjui-btn-blue',
           form:{id:'queryForm'},
           grid:{type:'datagrid','id':'productDg'}">查询</a>
    </form>
</div>
<!-- 表格工具栏结束 -->

<script>
    function saveSuccess(data) {
        console.log(data);
    }

    function deleteSuccess(data) {
        console.log(data);
    }

    function openEditDiag(uuid) {
        var $editDialog = $('<form></form>');
        $editDialog.iDialog({
            title: '编辑数据',
            width: 950,
            height: 500,
            closed: false,
            cache: false,
            href: _ctx + '/html/complex/dialog_edit.html?uuid=' + uuid,
            modal: true,
            buttons: [{
                text: '保存',
                iconCls: 'fa fa-save',
                btnCls: 'topjui-btn-blue',
                handler: function () {
                    // 提示信息
                    $.iMessager.alert('操作提示', '请根据具体情况编写代码，如ajax更新请求，请求失败提示，请求成功提示，请求成功后关闭窗口并刷新表格等！', 'messager-info');
                }
            }, {
                text: '关闭',
                iconCls: 'fa fa-close',
                btnCls: 'topjui-btn-red',
                handler: function () {
                    $editDialog.iDialog('close');
                }
            }],
            onLoad: function () {
                //加载表单数据
                $.getJSON(_ctx + '/json/datagrid/product-detail.json?uuid=' + uuid, function (data) {
                    $editDialog.form('load', data);
                });
            }
        });
    }

    function deleteRow(uuid) {
        $.iMessager.alert('操作提示', '请根据具体情况编写代码，如ajax删除请求，请求失败提示，请求成功提示，请求成功后刷新表格等！', 'messager-info');
    }

    // 自定义方法
    function myQuery() {
        // 提示信息
        $.iMessager.alert('自定义方法', '自定义方法被执行了！', 'messager-info');

        var checkedRows = $('#productDg').iDatagrid('getChecked');
        console.log(checkedRows);

        var selectedRow = $('#productDg').iDatagrid('getSelected');
        console.log(selectedRow);

        // 提交参数查询表格数据
        $('#productDg').iDatagrid('reload', {
            name: $('#name').iTextbox('getValue'),
            code: $('#code').iTextbox('getValue')
        });
    }

    function menuHandler(item) {
        item.menuType = 'menu-item';

        var t = $(item.extend);
        var etdOpts = t.length > 0 ? getOptionsJson(t) : {};
        var mOpts = $.extend(true, etdOpts, item);

        if (mOpts.method == 'openDialog') {
            openDialog(mOpts);
        }

        if (mOpts.method == 'doAjax') {
            doAjaxHandler(mOpts);
        }

        if (mOpts.method == 'export') {
            exportHandler(mOpts);
        }

        if (mOpts.method == 'request') {
            requestHandler(mOpts);
        }
    }
</script>
</body>
</html>
